//-----------------------------------------------------------------------
// <copyright file="DeleteAppPool.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <author>Andy Reeves [Updated: 22-2-08 Mike Fourie. Code Cleanup]</author>
// <email>andyr</email>
// <date>2004-03-23</date>
// <summary>Deletes the specfied Application Pool (IIS6 or later).</summary>
//-----------------------------------------------------------------------
namespace Microsoft.Sdc.Tasks.Web.DeleteAppPool
{
    using System;
    using Microsoft.Build.Framework;
    using Web = Microsoft.Sdc.Tasks.Configuration.Web;

    /// <summary>
    /// Deletes an existing Applcation Pool (IIS6 or later).
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[<Web.AppPool.DeleteAppPool AppPoolName="appPoolName"/>]]></code>
    /// <para>where:</para>
    /// <para><i>appPoolName (Required)</i></para>
    /// <para>A valid, existing IIS pool name</para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///         <Web.AppPool.DeleteAppPool
    ///             AppPoolName="TestApplicationPool"
    ///        />
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>    
    public class DeleteAppPool : TaskBase
    {
        private string name;
        private string machineName = "localhost";

        /// <summary>
        /// Machine to operate on
        /// </summary>
        public string MachineName
        {
            get { return this.machineName; }
            set { this.machineName = value; }
        }

        /// <summary>
        /// Name of the application pool to delete
        /// </summary>
        /// <value>Any valid, existing IIS application pool name</value>
        [Required]
        public string AppPoolName
        {
            get { return (this.name ?? String.Empty); }

            set { this.name = value; }
        }

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            if (Web.AppPool.Exists(this.AppPoolName, this.MachineName))
            {
                Log.LogMessageFromResources("Web.DeleteAppPool", this.AppPoolName);
                Web.AppPool.Delete(this.AppPoolName, this.MachineName);
            }
        }
    }
}